/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isd.pool.web;



import com.isd.pool.modelo.Pool;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import com.isd.pool.modelo.PoolTipo;
import com.isd.pool.rn.PoolRN;
import com.isd.pool.rn.PoolTipoRN;

/**
 *
 * @author ctrosch
 */
@ManagedBean (name="conversoresPool")
@SessionScoped
public class ConversoresPool {
    
    @EJB private PoolTipoRN poolTipoRN;
    @EJB private PoolRN poolRN;

    /** Creates a new instance of ConversoresBean */
    public ConversoresPool() {
        
    }
    
    public Converter getPool() {
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if (value.trim().equals("") || value == null) {
                    return null;
                }

                return poolRN.getPool(Integer.parseInt(value));
            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                if (value == null || value.equals("")) {
                    return "";
                } else {

                    return ((Pool) value).getNroPool()+ "";
                }
            }
        };
    }   
    

    public Converter getPoolTipo() {
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if (value.trim().equals("") || value == null) {
                    return null;
                }

                PoolTipo t = poolTipoRN.getPoolTipo(value);
                return t;
            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                if (value == null || value.equals("")) {
                    return "";
                } else {

                    return ((PoolTipo) value).getCodigo() + "";
                }
            }
        };
    }

   
}
